package com.example.designmode.strategyPattern;

import java.math.BigDecimal;

//实现折扣模式
public class FormLoad extends Strategy{

    //单价
    private double unitPrice;
    //数量
    private double number;
    //折扣
    private double discount;

    //通过构造方法实现数据填充
    public FormLoad(double unitPrice,double number,double discount){
        this.unitPrice = unitPrice;
        this.number = number;
        this.discount = discount;
    }

    @Override
    double AlgorithmInterface() {
        if (discount == 0){
            return new BigDecimal(unitPrice).multiply(new BigDecimal(number)).doubleValue();
        }
        BigDecimal multiply
                = new BigDecimal(unitPrice).multiply(new BigDecimal(number)).multiply(new BigDecimal(discount));
        return multiply.doubleValue();
    }
}
